﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Message : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSumit_Click(object sender, EventArgs e)
    {
        BZZ.DataAcess woker = new BZZ.DataAcess();
        BZZ.CommonFunctions cf = new BZZ.CommonFunctions();

        #region 获取数据
        string id = "0";//txtID.Text.Trim();
        string varNickName = txtNickName.Text.Trim();	//称呼
        string varTelephone = txtTelephone.Text.Trim();	//电话
        string varEmail = txtEmail.Text.Trim();	//邮箱
        string varQq = txtQq.Text.Trim();	//qq
        string varTitle = txtTitle.Text.Trim();	//标题
        string varContent = txtContent.Text.Trim();	//内容
        string varPubDate = DateTime.Now.ToString();// txtPubDate.Text.Trim();	//发布时间
        string varPubIP = cf.GetClientIP(this.Request);// txtPubIP.Text.Trim();	//发布ip
        string varIsread = "0";	//是否已读
        string varExt1 = "";// txtExt1.Text.Trim();	//扩展1
        string varExt2 = "";// txtExt2.Text.Trim();	//扩展2
        #endregion

        if (varNickName.Length < 2)
        {
            LIB.JsWrite.AlertAndGoback(this, "请输入您的姓名。");
        }
        if (varTelephone.Length < 7)
        {
            LIB.JsWrite.AlertAndGoback(this, "请输入您的电话。");
        }
        if (varTitle.Length < 6)
        {
            LIB.JsWrite.AlertAndGoback(this, "请输入标题。");
        }
        #region 拼接sql字符串操作
        string joinSql = "insert into [message](nickName,telephone,email,qq,title,content,pubDate,pubIP,isread,ext1,ext2)values('" + varNickName + "','" + varTelephone + "','" + varEmail + "','" + varQq + "','" + varTitle + "','" + varContent + "','" + varPubDate + "','" + varPubIP + "','" + varIsread + "','" + varExt1 + "','" + varExt2 + "')";
        if (id != "0") joinSql = "update message set [nickName]='" + varNickName + "',[telephone]='" + varTelephone + "',[email]='" + varEmail + "',[qq]='" + varQq + "',[title]='" + varTitle + "',[content]='" + varContent + "',[pubDate]='" + varPubDate + "',[pubIP]='" + varPubIP + "',[isread]='" + varIsread + "',[ext1]='" + varExt1 + "',[ext2]='" + varExt2 + "'  where id=" + id;
        //Response.Write(joinSql);
        //Response.End();
        int n = 0;
        try
        {
            n = woker.ExecuteNonQuery(joinSql);
        }
        catch (Exception ex)
        {
            Response.Write(cf.doneFailed(ex.Message.ToString(), "", 1));
            Response.End();
        }
        #endregion



        string msg = "";
        if (n > 0) msg = cf.doneOK("您的留言已提交，请等待管理员回复。","default.aspx");
        else msg = cf.doneFailed();
        Response.Write(msg);
    }

}
